clear
set more off
set scheme  s1mono 

global logs "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_public\logs"
global main "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_public"
global output "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_public\output"
global dat "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_public\data"
global programs "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_public\programs"
global sim_dat "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_public\simulated_data"

sysdir set PERSONAL "\\rschfs1x\userRS\a-e\clieberman_RS\Documents\rd graph\replication_final_internal\ado"

cd "${main}"

cap rmdir "${output}"
cap mkdir "${output}"

cap rmdir "${logs}"
cap mkdir "${logs}"

******************
* Software setup *
******************
* net install grc1leg, from( http://www.stata.com/users/vwiggins/) 
* ssc install estout
* ssc install sepscatter
* ssc install onewayplot
* ssc install moremata
* https://bitbucket.org/iacanay/car-stata
* http://cameron.econ.ucdavis.edu/research/cgmreg.ado
* net install rdmse, from(https://raw.githubusercontent.com/peizhuan/rdmse/master) replace

do "${programs}/rdplot7511.ado"
do "${programs}/rdplot7512.ado"
do "${programs}/rdplot7513.ado"
do "${programs}/rdplot7514.ado"
do "${programs}/rdplot7515.ado"

*********
* Build *
*********
* If running the build section instead of using supplied data, make note of software versions
* Be prepared for long runtime (about 3 hours on Carl's environment, with manual intervention for R and Mathematica scripts)

do "${programs}/asymptotic_variances_rdd.do"
do "${programs}/compute_gini_coefficients.do"

* Compute theoretical biases for the DGPs
* These calculations are done manually with hardcoded values and are included for completeness
do "${programs}/estimate_f0.do"
* Run Mathematica notebook
* theoretical_bw.nb
do "${programs}/theoretical_bias.do"

* Run rdhonest_estimates_subset.R. Be sure to update the directories at the top.
do "${programs}/rd_reg_micro.do"
do "${programs}/clean_expert_reported_discontinuities.do"
* Run confidence.R, again updating directories.

**********
* Output *
**********

do "${programs}/power_functions.do"
do "${programs}/power_analysis_experts_nonexperts.do"
do "${programs}/estimators_v_human_rd_experts_twoway_clustering.do"

do "${programs}/expert_pred_pref.do"
do "${programs}/experts_vs_estimators_rmse2.do"
do "${programs}/experts_vs_estimators_mse_decomposition2.do"
do "${programs}/es_vs_qs_gini.do"

do "${programs}/confidence_analysis_figs.do"

do "${programs}/tables_teffects_car.do"
do "${programs}/tables_covariate_balance.do"
do "${programs}/tables_covariate_prediction.do"
do "${programs}/tables_dgp_prediction.do"
do "${programs}/prior_analysis_all_phases.do"
do "${programs}/prior_analysis_all_phases_nickell_inference.do"
do "${programs}/decision_theory_risks.do"
do "${programs}/tables_confidence_effects_car.do"
do "${programs}/average_error_rates.do"
do "${programs}/dgp_histograms.do"
do "${programs}/dgp_cefs.do"